<template>
    <div>
        <h3>如何通过Axios实现异步请求发送</h3>
        <el-button type="primary" plain @click="httpGet">GET</el-button>
        <el-button type="primary" plain @click="httpPost">POST</el-button>
        <el-button type="primary" plain @click="httpPut">PUT</el-button>
        <el-button type="primary" plain @click="httpDelete">DELETE</el-button>
    </div>
</template>

<script>
// import {getObject, postObject, putObject, deleteObject} from "@/api/user";
import * as user from "@/api/user";

export default {
    name: "AxiosView",
    methods: {
        httpGet() {   //  get请求
            user.getObject().then(function (res) {
                console.log("请求成功", res)
            }).catch(function (err) {
                console.log("请求失败", err)
            })
        },
        httpPost() {  // post请求  默认会将参数转化为json格式

            user.postObject({username: 'tom', password: '123456'})
                .then(function (res) {
                    console.log("请求成功", res)
                }).catch(function (err) {
                console.log("请求失败", err)
            })
        },
        httpPut() {// put请求  默认会将参数转化为json格式
            user.putObject({username: 'tom', password: '123456'})
                .then(function (res) {
                    console.log("请求成功", res)
                }).catch(function (err) {
                console.log("请求失败", err)
            })
        },
        httpDelete() {// delete请求
            user.deleteObject(10).then(function (res) {
                console.log("请求成功", res)
            }).catch(function (err) {
                console.log("请求失败", err)
            })
        }
    }
}
</script>

<style scoped>

</style>